import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/homeView.vue'
import Welcome from '../components/Welcome'
import GearIndex from "@/views/ordering/picSetting.vue";
import ScoreList from "@/views/ordering/scoreList.vue";
import OrderingIndex from '@/views/ordering/index.vue'
import UserIndex from '@/views/users/index.vue'
import OrderList from "@/views/ordering/orderList.vue";
import Login from "@/views/login/index.vue";
import {getStore} from "js-utils";
import UserPanel from "@/views/users/userPanel.vue";
import MealManager from "@/views/ordering/mealManager.vue";
import CateIndex from "@/views/ordering/cateIndex.vue";
import ExpressIndex from "@/views/express/index.vue";
import Ticket from "@/views/ticket/index.vue";
import Board from "@/views/board/index.vue";
import MakingIndex from "@/views/ordering/makingIndex.vue";
import SpecIndex from "@/views/ordering/specIndex.vue";
import BeansData from "@/views/ticket/beansData.vue";
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    // redirect: '/welcome',
    redirect: '/orderingIndex',
    component: {render: c => c('router-view')},//https://blog.csdn.net/Marin6/article/details/122185133
    children: [//因为要在首页的页面嵌套显示welcome页面，所以需要以子路由的形式
      {path: '/welcome', component: Welcome,meta:{auth:true}},
      {path: '/picSetting', component: GearIndex,meta:{auth:true}},
      {path: '/orderingIndex', component: OrderingIndex,meta:{auth:true}},
      {path: '/orderList', component: OrderList,meta:{auth:true}},
      {path: '/userIndex', component: UserIndex,meta:{auth:true}},
      {path: '/scoreList', component: ScoreList,meta:{auth:true}},
      {path: '/userPanel', component: UserPanel,meta:{auth:true}},
      {path: '/mealManager', component: MealManager,meta:{auth:true}},
      {path: '/cateIndex', component: CateIndex,meta:{auth:true}},
      {path: '/expressIndex', component: ExpressIndex,meta:{auth:true}},
      {path: '/ticket', component: Ticket,meta:{auth:true}},
      {path: '/boardList', component: Board,meta:{auth:true}},
      {path: '/specIndex', component: SpecIndex,meta:{auth:true}},
      {path: '/makingIndex', component: MakingIndex,meta:{auth:true}},
      {path: '/beansData', component: BeansData,meta:{auth:true}},
    ],
    meta:{auth:true}
  },
  {
    path:'/login',
    name: 'login',
    component: Login
  }
]

const router = new VueRouter({
  routes
})

// 路由守卫
router.beforeEach((to,from,next)=>{
  next()
  // let token=getStore('token',true)
  // // 判断该页面是否需要登录
  // if(to.meta.auth){
  //   if(token){
  //     next()
  //   }else{
  //     next({
  //       path:'/login',
  //       // 跳转时传递参数到登录页面，以便登录后可以跳转到对应页面
  //       query:{
  //         redirect:to.fullPath
  //       }
  //     })
  //   }
  // }else{
  //   next()
  // }
})
export default router
